<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ include file="../common/header.jsp"%>
<section class="container">
	<div class="content-wrap">
		<form athion="" name="" class="shop_form" method="post" id="personForm">
			<div>
			<c:if test="${empty account.headImg }">
				<img id="preview-photo" style="float: left;"
					src="/news/resources/admin/easyui/images/user_photo.jpg"
					width="100px">
					</c:if>
					<c:if test="${ not empty account.headImg }">
				<img id="preview-photo" style="float: left;"
					src="${account.headImg}"
					width="100px">
					</c:if>
					<a style="float: left; margin-top: 40px;margin-right: 20px;"
					href="javascript:void(0)" class="easyui-linkbutton"
					iconCls="icon-upload" onclick="uploadPhoto()" plain="true">上传图片</a>
			</div>
			<ul>
			<li>
			<label>头像：</label>
						<input  style="width:500px;" type="text" id="add-photo" name="headImg" value="${account.headImg}" readonly="readonly" class="wu-text " />
			</li>
				<li><label>用户名称：</label><input type="text" id="username"
					name="username" value="${account.username}"></li>
				<li><label>密码：</label><input type="text" id="password"
					name="password" value="${account.password}" /></li>
				<li style="margin-left: 185px;"><label>手机号：</label><input type="text" id="phone"
					value="${account.phone}" name="phone"></li>
				<li style="margin-left:185px;"><label>年龄：</label><input
					type="text" id="age" value="${account.age}" name="age"></li>
				<li style="margin-left: 185px;"><label>性别:</label>
				<input type="radio" class="mr5" name="sex" value="0" <c:if test="${account.sex==0}">checked</c:if> />保密
				<input type="radio" class="ml10 mr5" name="sex" value="1" <c:if test="${account.sex==1}">checked</c:if> />男
				<input type="radio" class="ml10 mr5" name="sex" value="2" <c:if test="${account.sex==2}">checked</c:if>/>女</li>
				<li style="margin-left: 185px;"><label>住址：</label><input
					type="text" id="address" value="${account.address}" name="address"></li>
				<li class="bn" style="margin-left: 185px;"><label>&nbsp;</label><input type="button"
					onclick="editInfo()" class="form-submit" value="保存修改" /></li>
			</ul>
		</form>
	</div>


<div id="process-dialog" class="easyui-dialog" data-options="closed:true,iconCls:'icon-upload',title:'正在上传图片'" style="width:450px; padding:10px;">
<div id="p" class="easyui-progressbar" style="width:400px;" data-options="text:'正在上传中...'"></div>
</div>
<input type="file" id="photo-file" style="display:none;" onchange="upload()">
<script type="text/javascript">
function uploadPhoto(){
	$("#photo-file").click();
}

function upload(){
	if($("#photo-file").val() == '')return;
	var formData = new FormData();
	formData.append('photo',document.getElementById('photo-file').files[0]);
	$("#process-dialog").dialog('open');
	var interval = setInterval(start,200);
	$.ajax({
		url:'../admin/user/upload_photo',
		type:'post',
		data:formData,
		contentType:false,
		processData:false,
		success:function(data){
			clearInterval(interval);
			$("#process-dialog").dialog('close');
			if(data.type == 'success'){
			 	$("#preview-photo").attr('src',data.filepath);
				$("#add-photo").val(data.filepath);

			}else{
				$.messager.alert("消息提醒",data.msg,"warning");
			}
		},
		error:function(data){
			clearInterval(interval);
			$("#process-dialog").dialog('close');
			$.messager.alert("消息提醒","上传失败!","warning");
		}
	});
}


//上传图片
function start(){
		var value = $('#p').progressbar('getValue');
		if (value < 100){
			value += Math.floor(Math.random() * 10);
			$('#p').progressbar('setValue', value);
		}else{
			$('#p').progressbar('setValue',0)
		}
};

//修改个人信息
function editInfo(){
	var data=$('#personForm').serialize();
	$.ajax({
		url:'../index/updatePerson',
		dataType:'json',
		type:'post',
		data:data,
		success:function(data){
			if(data.type == 'success'){
			  alert(data.msg)
			  window.location.href="../index/index";
			}else{
				  alert(data.msg)
			}
		}
	});
}
</script>
	<%@ include file="../common/sidebar.jsp"%>
</section>

<%@ include file="../common/footer.jsp"%>
